<?php

namespace App\Http\Controllers\Web\Member\Seller;

use App\Http\Controllers\Web\BaseController;
use Illuminate\Http\Request;

class BrandAuditController extends BaseController
{
    protected $api_url = [
        'index' => ['get', 'seller/shop_brand'],
        'show' => ['get', 'seller/shop_brand/%d'],
        'store' => ['post', 'seller/shop_brand'],
//        'put' => ['put', ''],
//        'delete' => ['delete', ''],
    ];

    protected $api_host;

    protected $request;

    public function __construct(Request $request)
    {
        $this->request = $request;
        $this->api_host = config('url.api_web');
    }

    public function index()
    {
        $page = $this->request->get('page', 1);
        $params = [
            'search' => search_params([]),
            'searchJoin' => 'and',
            'page' => $page
        ];
        //请求部分
        $ret = http_web($this->api_url['index'])->send($params);

        //结果处理部分
        $data = paginate($this->request, $ret['data']);

        return view('web.user.seller.shop_brand', $data);
    }

    public function show($id)
    {

    }

    public function create(){

        return view('web.user.seller.shop_brand_info');

    }

    public function store(){

        //请求部分
        $data['shop_id'] = 1;

        $data=$this->request->all();
        
        $ret = http_web($this->api_url['store'])->send($data);

        if($ret['code']==0){
            return response()->json($ret);

        }else{
            return response()->json(['code'=>1,'message'=>'失败']);

        }
    }

    public function edit($id)
    {
        return view('form', ['type' => 'update']);
    }

    public function update($id)
    {
        $this->validate($this->request, [
            'sp_title' => 'required'
        ]);
        $data = $this->request->all([]);

        $ret = http_web($this->api_url['configure_update'],[$id])->send($data);

        if(isset($ret['code']) && $ret['code']===0 ){
            return response()->json(['code'=>0,'message'=>'']);
        }else{
            return response()->json(['code'=>1,'message'=>$ret['message']]);
        }

    }

    public function destroy()
    {

    }
}